package com.jie.staservice.schedule;

import com.jie.staservice.service.StatisticsDailyService;
import com.jie.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时任务类
 * @author XieZhiJie
 * @create 2020-10-18 14:25
 */
@Component
public class ScheduledTask {

    private final StatisticsDailyService dailyService;

    @Autowired
    public ScheduledTask(StatisticsDailyService dailyService) {
        this.dailyService = dailyService;
    }

    // 可行
//    @Scheduled(cron = "0/5 * * * * ?")
//    public void test() {
//        System.out.println("hhh");
//    }

    // 每天凌晨1点, 执行方法, 把前一天的数据查询执行添加
    @Scheduled(cron = "0 0 1 * * ?")
    public void task() {
        dailyService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
    }

}
